/**
 * 
 */
package org.dragonfire.dasm.directives;

import java.util.ArrayList;

import org.dragonfire.dasm.Command;
import org.dragonfire.dasm.Listing;
import org.dragonfire.dasm.DirectiveManager.Directive;
import org.dragonfire.parser.Equation;
import org.dragonfire.util.DString;

/**
 * Prints the specified text out to the logfile/console at the current cursor
 * position<br />
 * <br />
 * Format:<br />
 * <code>#ECHO <i>&lt;arg1&gt;</i>[,<i>&lt;arg2&gt;</i>[,<i>...</i>]]</code><br />
 * <br />
 * Parameters:<br />
 * <table>
 * <tr>
 * <td><code>arg1</code></td>
 * <td>(Double/String) The text to be placed into the log file.</td>
 * </tr>
 * </table><br />
 * Errors:<br />
 * <i>None</i>
 * 
 * @author Darth Android
 * @see org.dragonfire.dasm.directives.Echoln
 * @see org.dragonfire.dasm.DASM#log(String)
 * @version 2.0
 */
public class Echo extends Directive {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ArrayList<Listing> pass1(Command c) {
		ArrayList<Listing> list = new ArrayList<Listing>();
		for (int i = 0; i < c.getParams().length; i++) {
			// remove static parts
			c.getParams()[i] = evalStatics(c.getParams()[i]);
			// add for second pass
		}
		list.add(new Listing(0, c));
		return list;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void pass2(Listing lst, Command c) {
		for (String s : c.getParams()) {
			// evaluate & print
			s = eval(s);
			// extract it if it's a string
			if (Equation.isString(s))
				s = DString.extractString(s);
			log(s);
		}
	}
}
